package com.acme;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class Accolade {

	String name;
	String year;
	String id;
	String type;
	
	public static ArrayList<Accolade> getAccolades(String accoladesJson){
		
		try {
			return getAccolades(new JSONArray(accoladesJson));
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public static ArrayList<Accolade> getAccolades(JSONArray accoladesJson){
		
		ArrayList<Accolade> accolades = new ArrayList<Accolade>();
		
		try {
			
			int length = accoladesJson.length();
			
			for (int i = 0; i < length; i++){
				
				JSONObject accoladeJson = accoladesJson.getJSONObject(i);
				
				Accolade accolade = new Accolade();
				accolade.name = accoladeJson.getString("award_title");
				accolade.year = accoladeJson.getString("year");
				accolade.id = accoladeJson.getString("id");
				accolade.type = accoladeJson.getString("type");
				
				accolades.add(accolade);
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
		return accolades;
	}
}
